
# import sklearn
# from sklearn import preprocessing
# import pandas as pd
# import numpy as np
# from sklearn.experimental import enable_iterative_imputer
# from sklearn.impute import IterativeImputer
# from sklearn.preprocessing import MinMaxScaler
# from sklearn.preprocessing import MaxAbsScaler


# from sklearn.preprocessing import StandardScaler as ss
# scaler = ss() # 实例化
# X_train = [[1,-1,2],[2,0,4],[3,2,-6]]
# scaler.fit(X_train) # 在训练集上训练，得到均值和方差
# print('mean',scaler.mean_) #查看得到的均值
# print('std',scaler.scale_) #查看得到的方差
# X_train_re = scaler.transform(X_train) # 在训练集上归一化
# print('X_train_re',X_train_re) #打印训练集归一化的结果
# X_test_re = scaler.transform([[1,2,3]]) #在测试集上归一化
# print('X_test_re',X_test_re)

# 标签编码（LabelEncoder） 
# from sklearn.preprocessing import LabelEncoder
# le = LabelEncoder() # 实例化
# le.fit(["beijing","shanghai","beijing","shenzhen"])
# print("labels",list(le.classes_)) # 打印所有的标签集合
# print(le.transform(["beijing","shanghai"])) # 打印给定标签对应的编码
# print(list(le.inverse_transform([2,2,1]))) # 打印编码对应的原始标签
# 多标签二值化编码（MultiLabelBinarizer）
# from sklearn.preprocessing import MultiLabelBinarizer
# import numpy as np
# mlb = MultiLabelBinarizer() # 实例化
# Y = [['beijing','chengdu'],['chengdu','tianjin'],['chongqing'],['guangzhou'],['shanghai'],['shenzhen'],['tianjin']]
# mlb.fit(Y) # 训练标签数据
# print('codeing:',mlb.transform([['beijing','shanghai']])) # 打印新标签编码结果
      
# 特征按序编码（OrdinalEncoder） 
# from sklearn.preprocessing import OrdinalEncoder
# oe = OrdinalEncoder() # 实例化
# X = [['male','beijing'],['female','shenzhen'],['male','shanghai']]
# oe.fit(X) # 进行训练
# print("categories:",oe.categories_) # 打印类别
# print("encode:",oe.transform([['male','shenzhen'],['female','beijing']]))

# 独热编码（OneHotEncoder）
# from sklearn.preprocessing import OneHotEncoder
# ohe = OneHotEncoder()
# X = [['male','beijing'],['female','shanghai'],['male','shenzhen'],['female','beijing']]
# ohe.fit(X)
# print('categories:',ohe.categories_) # 查看特征取值
# print('encode:',ohe.transform([['female','shenzhen']]).toarray()) # 输出特征编码

# K-bins离散化（KBinsDiscretizer）
# from sklearn.preprocessing import KBinsDiscretizer
# import numpy as np
# X = np.array([[-3,5,15],[0,6,14],[6,3,11]])
# kbd = KBinsDiscretizer(n_bins=[3,2,2],encode='ordinal')
# kbd.fit(X)
# print('Edge:',kbd.bin_edges_) # 显示分箱边界
# print('codeing:',kbd.transform(X)) # 对训练数据的离散结果
# print('codeing:',kbd.transform([[-10,2,0],[-1,5.5,16]])) # 对新数据的离散结果

# 二值化（Binarizer） 
# from sklearn.preprocessing import Binarizer
# X = [[1.,-1.,2.],[2.,0.,0.],[0.,1.2,-1.]]
# binarizer = Binarizer(threshold=1.).fit(X)
# print(binarizer.transform(X))

# X_tr = [[1,-1,2],[2,0,0],[0,-2,-1]]
# mas = MaxAbsScaler() # 实例化MaxAbsScaler对象
# X_re = mas.fit_transform(X_tr) # 注意先进行fit,后进行transform
# # print(X_re)
# print(mas.transform([[5,-5,3]]))

# X_train = [[1,-1,2],[2,0,0],[0,1,-1]]
# min_max_scaler = MinMaxScaler(feature_range=(0,1))
# X_train_minmax = min_max_scaler.fit_transform(X_train)
# print(X_train_minmax)

# imp = IterativeImputer(missing_values=np.nan)
# imp.fit([[1,3],[2,5],[3,7]]) # 对每一列使用其他列进行回归
# X_test = [[np.nan,11],[6,np.nan],[np.nan,6],[3,17]] # 原始数据
# print(imp.transform(X_test)) # 打印插值后的数据

# i3 = SimpleImputer(missing_values=np.nan,strategy='mean')
# print(i3.fit_transform([[np.nan,1,3],[0,np.nan,2],[4,3,1]]))

# i4 = SimpleImputer(missing_values='',strategy='most_frequent')
# p = pd.DataFrame([['','k','x'],['a','m',''],['b','','y'],['a','m','x']],dtype='category') # 定义DataFrame对象
# print(i4.fit_transform(p))

# 定义Imputer对象
# i = SimpleImputer(missing_values=0,strategy='constant',fill_value=10)
# i.fit([[0,1,2]]) # fit()函数让Imputer对象适应（拟合）数据，参数为2维数组
# X = np.array([[0,1,2],[6,0,5],[7,8,0]]) # 原始数据，列数应与fit函数参数列数相同
# X1 = i.transform(X) # 将X中的所有缺失值填补，返回填补后的二维数组
# print(X1,type(X1))

# i2 = SimpleImputer(missing_values=0,strategy='constant',fill_value=10)
# X = np.array([[0,1,2,0],[6,0,5,0],[7,8,0,0]]) # 原始数据，3行4列
# X2 = i2.fit_transform(X) # 先fit后进行transform操作，返回填补后的二维数组
# print(X2,type(X2))


